var StepForm = (function($) {
	var s,
	settings = {
		stepForm: $('.js-step-form'),
		stepSwiper: undefined,
		fields: $('.js-required'),
		submitBtn: $('.js-confirm')
	};
	
	/**
	 * 初始化模块
	 */
	var fire = function() {
		s = settings;
		_bindUIActions();
	};
	
	/**
	 * 绑定UI事件
	 */
	var _bindUIActions = function() {
		/**
         * 分步表单
         */
        s.stepSwiper = new Swiper('.js-step-form', {
            pagination: '.swiper-pagination',
            slidesPerView: 'auto',
            paginationClickable: true,
            slidesOffsetBefore: 15,
            slidesOffsetAfter: 15,
            spaceBetween: 15
        });

        s.submitBtn.on('click', function(event) {
        	event.preventDefault();
        	if( _validateForm() ) {
        		_submitForm();
        	}
        });
	}

	/**
	 * 提交表单
	 */
	var _submitForm = function() {
		swal({
            title: "确认提交",
            text: "您的电影客约见申请将被提交。如果电影咖未通过您申请，可以修改后再次提交。",
            showCancelButton: true,
            confirmButtonColor: "#00aaee",
            confirmButtonText: "提交审核",
            cancelButtonText: "修改",
            closeOnConfirm: false
        }, function() {
            s.stepForm.submit();
        });
	};

	/**
	 * 验证表单分步
	 */
	var _validateForm = function() {

		var $fields = $('.js-step-form .js-required'),
            flag = 0;

        $fields.each(function(index, el) {
            if($(this).val() == '') {
                flag = 1;
            }
        });

        if(flag) {
            alert('你的信息填写不完整，请重新检查！');
            return false;
        }

        // 检查手机号
        var phoneNum = $('.js-step-form .js-phone').val();
        if( checkMobile(phoneNum) == false && phoneNum !== undefined ) {
            alert('手机号不正确，请重新输入！');
            return false;
        }
        
        return true;
	};

	return {
		fire: fire
	}
	
})(Zepto);